package com.quanshu.exchange.ui.gui.message.group.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

/**
 * Created by jye on 2018/1/17.
 */

public class DialogGroupMenu extends BaseDialog {
    @BindView(R.id.send_doc)
    TextView sendDoc;
    @BindView(R.id.send_doc_layout)
    LinearLayout sendDocLayout;
    @BindView(R.id.check_doc)
    TextView checkDoc;
    @BindView(R.id.check_group_detail)
    TextView checkGroupDetail;
    @BindView(R.id.update_group_detail)
    TextView updateGroupDetail;
    @BindView(R.id.update_group_detail_layout)
    LinearLayout updateGroupDetailLayout;

    private BehaviorSubject sendDocSubject = BehaviorSubject.create();
    private BehaviorSubject checkDocSubject = BehaviorSubject.create();
    private BehaviorSubject checkDetailSubject = BehaviorSubject.create();
    private BehaviorSubject updDetailSubject = BehaviorSubject.create();

    public DialogGroupMenu(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_group_menu);
        ButterKnife.bind(this);
        initListener();
    }

    public void setIsOwner(boolean flag) {
        // 是群主
        if (flag) {
            updateGroupDetailLayout.setVisibility(View.VISIBLE);
        } else {
            updateGroupDetailLayout.setVisibility(View.GONE);
        }
    }

    @Override
    public void init(@NonNull Context context) {
        Window window = getWindow();
        window.setWindowAnimations(R.style.TopAnim);
        window.setGravity(Gravity.TOP);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    @Override
    public boolean isCancelAble() {
        return true;
    }

    private void initListener() {
        RxViewHelper.getInstance().clicks(sendDoc, aVoid -> sendDocSubject.onNext(aVoid));
        RxViewHelper.getInstance().clicks(checkDoc, aVoid -> checkDocSubject.onNext(aVoid));
        RxViewHelper.getInstance().clicks(checkGroupDetail, aVoid -> checkDetailSubject.onNext(aVoid));
        RxViewHelper.getInstance().clicks(updateGroupDetail, aVoid -> updDetailSubject.onNext(aVoid));
    }

    public BehaviorSubject getSendDocSubject() {
        return sendDocSubject;
    }

    public BehaviorSubject getCheckDocSubject() {
        return checkDocSubject;
    }

    public BehaviorSubject getCheckDetailSubject() {
        return checkDetailSubject;
    }

    public BehaviorSubject getUpdDetailSubject() {
        return updDetailSubject;
    }
}
